﻿using Microsoft.AspNetCore.Mvc;
using MyCommon.Filter;
using MyDomain.Api;

namespace MyCommon.MVC
{
    [ApiActionFilter, ApiExceptFilter]
    public class BaseController : Controller
    {
        #region Result

        /// <summary>
        /// 404
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        [Route("error/{code}")]
        public ApiResult Error(int code)
        {
            return new ApiResult(false, "接口请求错误!", code);
        }

        [NonAction]

        public virtual ApiResult Result(bool success, string msg, int code)
        {
            return new ApiResult(success, msg, code);
        }

        [NonAction]
        public virtual ApiResult Result(bool success, object obj, int code)
        {
            return new ApiResult(success, obj, code);
        }

        [NonAction]
        public virtual ApiResult Result(string msg)
        {
            return new ApiResult(msg);
        }

        [NonAction]
        public virtual ApiResult Result(object obj)
        {
            return new ApiResult(obj);
        }

        [NonAction]
        public virtual ApiResult SuccessResult(string msg)
        {
            return new ApiResult(true, msg, 200);
        }

        [NonAction]
        public virtual ApiResult SuccessResult(object obj)
        {
            return new ApiResult(true, obj, 200);
        }

        [NonAction]
        public virtual ApiResult SuccessResult(string msg, int code)
        {
            return new ApiResult(true, msg, code);
        }

        [NonAction]
        public virtual ApiResult SuccessResult(object obj, int code)
        {
            return new ApiResult(true, obj, code);
        }

        [NonAction]
        public virtual ApiResult FailResult(string msg)
        {
            return new ApiResult(true, msg, 500);
        }

        [NonAction]
        public virtual ApiResult FailResult(object obj)
        {
            return new ApiResult(true, obj, 500);
        }

        [NonAction]
        public virtual ApiResult FailResult(string msg, int code)
        {
            return new ApiResult(true, msg, code);
        }

        [NonAction]
        public virtual ApiResult FailResult(object obj, int code)
        {
            return new ApiResult(true, obj, code);
        }

        #endregion
    }
}
